define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'supplier/index',
                    add_url: '',
                    edit_url: '',
                    del_url: 'supplier/del',
                    multi_url: 'supplier/multi',
                    table: 'supplier',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showToggle: false,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: 'ID', operate:false},
                        {field: 'avatar', title: '头像', operate:false,formatter: Table.api.formatter.image},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE %...%'},
                        {field: 'type_text', title: __('Type'), operate:false},
                        {field: 'name', title: __('Name'), operate: 'LIKE %...%'},
                        /*{field: 'address', title: __('Address'), operate: 'LIKE %...%'},
                        {field: 'person', title: __('Person'), operate: 'LIKE %...%'},
                        {field: 'person_mobile', title: __('Person_mobile'), operate: 'LIKE %...%'},*/
                        {field: 'sum_income', title: __('Sum_income'), operate:false},
                        {field: 'wallet_money', title: __('Wallet_money'), operate:false},
                        {field: 'cash', title: __('Cash'), operate:false},
                        {field: 'state_text', title: __('State'), operate:false,formatter: Table.api.formatter.label},
                        {field: 'operate', title: __('Operate'), table: table, 
                            buttons:[{
                                name: 'aclist', 
                                text: '活动列表', 
                                classname: 'btn btn-xs btn-info btn-fields btn-addtabs', 
                                icon: 'fa fa-list', 
                                url: 'activity/index?supplier_id={ids}'
                            },
                            {
                                name: 'detail', 
                                text: '详情', 
                                classname: 'btn btn-xs btn-info btn-detail btn-dialog', 
                                icon: 'fa fa-list', 
                                url: 'supplier/detail'
                            }],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});